var LIMIT = 20;
var START = 0;
var searchKey = "";
var _ulId = "ul_standard";
var div_loadMore;
var self;
window.addEventListener("refreshList", function() {
	window.location.reload();
})

mui.init();
mui.plusReady(function() {
	self = plus.webview.currentWebview();
	initData(self.type);
	initListener();
});


//蒙版隐藏
window.addEventListener("closeMask", function() {
	mui(".mui-backdrop")[0].classList.add("mui-hidden");
});
//蒙版显示
window.addEventListener("showMask", function() {
	mui(".mui-backdrop")[0].classList.remove("mui-hidden");
});

/*
 * 初始化防汛工程数据
 */

function initData(knowledgeType) {
	div_loadMore = mui("#div_standardMore")[0];
	var params = {
		"start": START,
		"limit": LIMIT,
		"zsmc": searchKey,
		"zslx": knowledgeType
	}
	plus.nativeUI.showWaiting();

	ajaxF1(GETKOWNLEDGE, params, function(data) {
		if(data.successful == true) {
			//判断加载更多的显隐
			if(data.resultValue.length == LIMIT) {
				mui(".loadMore").each(function() {
					if(this.id == div_loadMore.id) {
						this.classList.remove("mui-hidden");
					}
				})
			} else {
				mui(".loadMore").each(function() {
					if(!this.classList.contains("mui-hidden")) {
						this.classList.add("mui-hidden");
					}
				})
			}

			if(data.resultValue.zdlist.length == 0 && START == 0) {
				$("#" + _ulId).append('<div class="div_no_message">暂无文档</div>');
			}
			showFile(_ulId, data.resultValue.zdlist, true, knowledgeType);
		} else {
			mui.toast(data.resultHint);
		}
		plus.nativeUI.closeWaiting();
	}, function() {
		plus.nativeUI.closeWaiting();
		mui.toast("网络请求失败")
	})
}

function initListener() {

	//点击加载更多的点击事件
	mui(".mui-content").on("tap", ".loadMore", function() {
		START++;
		//给每个“加载更多”按钮绑定其特定的start
		initData(self.type)
	})
	$(".icon_back").on("tap", function() {
		mui.back();
	});

}